<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">


    <link rel="stylesheet" href="${AppPath}/css/font-awesome.min.css">
    <link rel="stylesheet" href="${AppPath}/css/login.css"/>
    <link rel="stylesheet" href="${AppPath}/layer/skin/default/layer.css">

</head>
<body>
<div class="login">
    <div class="content clearfix">
        <div class="content-left">
            <div class="logo">
                <img src="${AppPath}/img/logo.png" alt=""  title="蜗牛第一小组教学管理系统"/>
                <p>&copy;蜗牛第一小组教学管理系统</p>
            </div>
        </div>
        <div class="shu"></div>
        <form action="" method="post" id="userlogin">
        <div class="content-right">
            <div class="login-form">
                <h2>用户登录/LOGIN</h2>
                <div class="identifire">
                    <span>身　份：</span>
                    <select name="roleStatus" id="role" >
                        <option selected=selected  value="2">学生</option>

                        <option  value="3">公司</option>
                        <option   value="1">员工</option>

                    </select>
                </div>

                <div class="account clearfix">
                    <span>账　号：</span>
                    <input name="userName" type="text" value="" />
                    <span id="username" ></span>
                </div>

                <div class="password clearfix">
                    <span>密　码：</span>
                    <input name="userPwd" type="password" value="" />
                    <span id="userpwd" ></span>
                </div>

                <div class="code clearfix">
                    <span>验证码：</span>
                    <input type="text" name="checkCode" value="" />
                    <em><img  id="checkcodeimg" src="${AppPath}/checkcode" onclick="this.src='${AppPath}/checkcode?t='+Math.random()" /></em>
                    <span id="checkcode" ></span>

                </div>
                <div class="btn">
                    <span id="login"><a>登录</a></span>
                    <span class="forget"><a href="password.html">忘记密码</a></span>
                </div>
            </div>
        </div>
        </form>
    </div>

</div>
<script src="${AppPath}/js/jquery-1.9.1.min.js"></script>
<script src="${AppPath}/layer/layer.js"></script>
<script type="text/javascript">
    $(document).ready(function(){

        var b=true;
        jiaoyanpwd(b);
        jiaoyanname(b);

        if($("input[name=userName]").val()!=null&&$("input[name=userPwd]").val()!=null&&b){
            $("#login").click(function () {

                $.ajax({
                    url:"${AppPath}/getcheckcode",
                    type:"post",
                    success:function (data) {
                        var  code=$("input[name=checkCode]").val();

                        if(data.toUpperCase()!=code.toUpperCase()){
                            layer.msg("验证码不正确",{time:1000,icon:5,shift:6},function () {

                            })
                        }else {

                                $.ajax({
                                    url:"${AppPath}/login",
                                    data:$("#userlogin").serialize(),
                                    type:"post",
                                    error:function(){
                                        alert("error");
                                    },
                                    success:function(data){

                                        if(data.result=="ok"){
                                            layer.msg("欢迎进入蜗牛第一小组教学管理系统",{time:1000,icon:6},function () {
                                               location.href="${AppPath}/main";
                                            });
                                        }else{
                                            layer.msg("不存在该用户,请重新输入",{time:1500,icon:5,shift:6},function () {
                                               location.href="${AppPath}/quit"
                                            });

                                        }
                                    }

                                })

                              }
                       }
                   })

            })
        }
    });


    function jiaoyanname(b) {
        $("input[name=userName]").blur(function () {
            var username=$(this).val();

            var zz=/^[a-zA-Z]\w{5,11}$/;
            if(!zz.test(username)){

                    layer.msg("用户名称不合法,请仔细查看",{time:1000,icon:5,shift:6},function () {

                    })



               b=false;
            }
        })


    }
    function jiaoyanpwd(b) {
        $("input[name=userPwd]").blur(function () {
            var pwd=/^\w{6,12}$/;
            var userPwd=$(this).val();

            if(!pwd.test(userPwd)){
                layer.msg("用户名密码应大于6位",{time:1000,icon:5,shift:6},function () {
                })
                b= false;
            }
        })
    }

</script>

</body>
</html>

